package edu.scau.mis.sys.utils;

import edu.scau.mis.sys.security.service.TokenService;
import net.sf.json.JSONObject;

import javax.servlet.http.HttpServletRequest;

/**
 * 获取请求头数据
 */
public class HttpServletRequestUtils {

    /**
     * 获取微信小程序请求头中的openid
     *
     * @return
     */
    public static String getOpenid(HttpServletRequest httpServletRequest){
        //获取请求头token
        String token = httpServletRequest.getHeader("Authorization");
        String session = TokenService.parseToken(token).getSubject().substring(4);
        String openid = JSONObject.fromObject(session).getString("openid");

        return openid;
    }

}
